import 'dart:io';
import 'package:dog_read/provider/providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'routes/route.dart';
import 'package:provider/provider.dart';

void main() {
  // debugPaintSizeEnabled=true;
  runApp(MyApp());
  if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle =
      SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,//状态栏
        // systemNavigationBarColor:Colors.transparent,//虚拟按键背景色
        // systemNavigationBarDividerColor: Colors.transparent,
        // systemNavigationBarIconBrightness: Brightness.dark,//虚拟按键图标色
        // statusBarIconBrightness: Brightness.light,
        // statusBarBrightness: Brightness.light,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top, SystemUiOverlay.bottom]);
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        /// 注意MultiProvider的用法！
        providers: [
          ChangeNotifierProvider<ChapterInfosProvider>.value(value: ChapterInfosProvider()),
          ChangeNotifierProvider<PageControlProvider>.value(value: PageControlProvider()),
          ChangeNotifierProvider<BookshelfProvider>.value(value: BookshelfProvider()),
          ChangeNotifierProvider<ShelfProvider>.value(value: ShelfProvider()),
        ],
        child: MaterialApp(
            debugShowCheckedModeBanner: false,
            title: '青读',
            theme: ThemeData(
              primarySwatch: Colors.yellow,
              bottomSheetTheme: BottomSheetThemeData(
              backgroundColor: Colors.transparent
              ),    
            ),
            initialRoute: "/",
            // routes: routes,  // 必须去掉route才能用onGenerateRoute
            onGenerateRoute: onGenerateRoute));
  }
}
